package com.andy.beef.ui.main.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.text.InputFilter
import androidx.activity.viewModels
import com.andy.beef.R
import com.andy.module.base.BaseVbActivity
import com.andy.module.ext.addTextCheck
import com.andy.module.ext.addToolBar
import com.andy.module.ext.initUploadFragment
import com.andy.module.util.NumberInputFilter
import com.andy.module.util.PatternInputFilter
import com.andy.module.util.RegConstant
import com.andy.module.util.choose.CodeChooseManager
import com.andy.module.util.choose.DateChooseManager
import com.andy.beef.databinding.MainActivityEditFarmCattleBinding
import com.andy.beef.main.bean.CattleInfoBean
import com.andy.beef.ui.main.bean.FenceBean
import com.andy.beef.ui.main.bean.group.WagyEnumGroupBean
import com.andy.beef.ui.main.viewmodel.EditFarmCattleViewModel
import com.andy.beef.ui.main.viewmodel.WagyEnumModel
import com.andy.module.uploadphoto.UploadPhotoFragment
import com.andy.ui.ext.clickNoRepeat

/**
 * @creator:LuoFan
 * @date:2022/6/10
 * @description:
 */
class EditFarmCattleActivity : BaseVbActivity<EditFarmCattleViewModel, MainActivityEditFarmCattleBinding>() {

//    private lateinit var photoFragment: UploadPhotoFragment
//
//    private var cattleInfo: CattleInfoBean? = null
//
//    private lateinit var birthDayChooser: DateChooseManager
//
//    private lateinit var coreGroupChooser: CodeChooseManager
//
//    private lateinit var brandChooser: CodeChooseManager
//
//    private var chooseFence: FenceBean? = null
//
//    val wagyEnumModel: WagyEnumModel by viewModels()

    override fun initView(savedInstanceState: Bundle?) {
//        initArgument()
//        addLoadingObserve(wagyEnumModel)
//        val customToolBar = mViewBind.root.addToolBar(title = "牛只新增") {
//            finish()
//        }
//        customToolBar.setRightBtnText("保存")
//        customToolBar.getRightBtn().clickNoRepeat {
//            addCattle()
//        }
//        photoFragment = mViewBind.photoLayout.initUploadFragment(fragmentManager = supportFragmentManager, layoutId = R.id.photo_layout)
//        mViewBind.etWeight.filters = arrayOf<InputFilter>(NumberInputFilter(9999999.99, 2))
//        mViewBind.etParity.filters = arrayOf<InputFilter>(PatternInputFilter(RegConstant.NUMBER_TWO_INPUT))
//        mViewBind.tvLair.clickNoRepeat {
//            ChooseFenceActivity.startMeForResult(this, ChooseFenceActivity.CODE)
//        }
//        initCheck()
//        initChooseManager()
    }

//    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
//        super.onActivityResult(requestCode, resultCode, data)
//        if (resultCode == Activity.RESULT_OK) {
//            when (requestCode) {
//                ChooseFenceActivity.CODE -> {
//                    chooseFence = data!!.getSerializableExtra(ChooseFenceActivity.RESULT_DATA) as FenceBean
//                    mViewBind.tvLair.text = chooseFence!!.fenceName
//                }
//            }
//        }
//    }
//
//    private fun initChooseManager() {
//        coreGroupChooser = CodeChooseManager(mViewBind.tvCoreGroup, getString(R.string.main_is_core_group))
//        coreGroupChooser.setDataSource(CodeChooseManager.genYesNoCodeList(this))
//        birthDayChooser = DateChooseManager(mViewBind.tvBirthday, getString(R.string.main_birthday))
//        brandChooser = CodeChooseManager(mViewBind.tvBrand, "品种")
//        brandChooser.setDataLoader(wagyEnumModel, WagyEnumGroupBean.BREED_CATEGORY)
//    }
//
//    private fun initCheck() {
//        mViewBind.llCowNum.addTextCheck(mViewBind.etNo)
//        mViewBind.llBirthday.addTextCheck(mViewBind.tvBirthday)
//        mViewBind.llBrand.addTextCheck(mViewBind.tvBrand)
//        mViewBind.llSex.addTextCheck(mViewBind.tvSex)
//        mViewBind.llWeight.addTextCheck(mViewBind.etWeight)
//        mViewBind.llEnterTime.addTextCheck(mViewBind.tvEnterTime)
//        mViewBind.llLair.addTextCheck(mViewBind.tvLair)
//        mViewBind.llSku.addTextCheck(mViewBind.tvSku)
//    }
//
//    private fun initArgument() {
//        cattleInfo = intent.getSerializableExtra(CATTLE_INFO) as CattleInfoBean?
//    }
//
//    private fun addCattle() {
//        val params = genParams()
//        mViewModel.addCattle(params)
//    }
//
//    private fun genParams(): HashMap<String, Any> {
//        val params = HashMap<String, Any>()
////        if (mCowInfoBean != null) {
////            params.with("id", mCowInfoBean!!.cattleId)
////        }
//        chooseFence?.let {
//            params["cattleFenceId"] = it.fenceId
//        }
//        params["purchaseOrderNo"] = mViewBind.etPurchaseNo.text.toString()
//        params["cattleEarTagNo"] = mViewBind.etNo.text.toString()
//        params["usedNo"] = mViewBind.etUsedNo.text.toString()
//        params["rfidCode"] = mViewBind.etEarTag.text.toString()
//        if (birthDayChooser.chooseTime > 0) {
//            params["birthday"] = birthDayChooser.chooseTime
//        }
////        if (brandCodeManager.chooseCode != null) {
////            params.with("variety", "${brandCodeManager.chooseCode!!.code}")
////        }
////        if (sexCodeManager.chooseCode != null) {
////            params.with("gender", "${sexCodeManager.chooseCode!!.code}")
////        }
////        params.withCheckNull("initWeight", et_weight.text.toString().trim())
////        if (ll_parity.visibility == View.VISIBLE) {
////            params.withCheckNull("currentChildTime", et_parity.text.toString().trim())
////        }
////        if (enterTime > 0) {
////            params.with("entryDate", "$enterTime")
////        }
////        if (feedTypeCodeManager.chooseCode != null) {
////            params.with("feedType", "${feedTypeCodeManager.chooseCode!!.code}")
////        }
////        if (coreGroupCodeManger.chooseCode != null) {
////            params.with("nucleusGroupStatus", "${coreGroupCodeManger.chooseCode!!.code}")
////        }
////        params.withCheckNull("fatherNo", et_father.text.toString().trim())
////        params.withCheckNull("motherNo", et_mother.text.toString().trim())
////        params.withCheckNull("insureNo", et_policy_number.text.toString().trim())
////        var photoList = photoFragment.uploadFileServerSource
////        if (photoList.isNotEmpty()) {
////            var photoParamsMap = mPresenter.getUploadPhotoSource(photoList)
////            params.with("pics", JSON.toJSONString(photoParamsMap))
////        }
////        params.withCheckNull("skuCode", tv_sku.text.toString().trim())
//        return params
//    }

    override fun createObserver() {
        super.createObserver()
        mViewModel.addResultData.observe(this) {

        }
        mViewModel.editResultData.observe(this) {

        }
    }

    companion object {
        const val CATTLE_INFO = "cattleInfo"
    }
}